package org.sport.repository;

import org.sport.model.entityModel.UsertableEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;


@Repository
public interface UserRepository extends JpaRepository<UsertableEntity, Integer> {



    @Transactional
    @Query("select usertableentity from UsertableEntity usertableentity where usertableentity.phoneNumber =:phoneNumber")
    public UsertableEntity finduserByPhoneNumber(@Param("phoneNumber") String phoneNumber);

    @Modifying
    @Transactional
    @Query("update UsertableEntity us set us.phoneNumber=:qPhoneNumber, " +
            "us.name=:qName, " +
            "us.password=:qPassword, " +
            "us.email=:qEmail, " +
            "us.brief=:qBrief,"+
            "us.headIcon=:qHeadIcon,"+
            "us.idCardNumber=:qIdCardNumber,"+
            "us.birthday=:qBirthday,"+
            "us.awardNumber=:qAwardNumber,"+
            "us.punchNumber=:qPunchNumber,"+
            "us.punchToday=:qPunchToday where us.id=:qId")
    public void updateUser(@Param("qPhoneNumber") String phoneNumber,
                           @Param("qName") String name,
                           @Param("qPassword") String password,
                           @Param("qEmail") String email,
                           @Param("qBrief") String brief,
                           @Param("qHeadIcon") String headIcon,
                           @Param("qIdCardNumber") String idCardNumber,
                           @Param("qBirthday") Timestamp birthday,
                           //                      @Param("qCreateDay") Timestamp email,
                           @Param("qAwardNumber") Integer awardNumber,
                           @Param("qPunchNumber") Integer punchNumber,
                           @Param("qPunchToday") Integer punchToday,
                           @Param("qId") Integer id
    );
}
